import json
import os
from tkinter import messagebox

def data_manager():
    # 数据存储路径
    DATA_FILE = "tasks.json"

    def save_data(tasks):
        try:
            with open(DATA_FILE, 'w') as file:
                json.dump(tasks, file)
        except Exception as e:
            messagebox.showerror("Error saving data", str(e))

    def load_data():
        try:
            if os.path.exists(DATA_FILE):
                with open(DATA_FILE, 'r') as file:
                    return json.load(file)
            else:
                return []
        except Exception as e:
            messagebox.showerror("Error loading data", str(e))
            return []